package com.chixigua.chaos.config.security.auth;

import com.chixigua.chaos.utils.CustomExceptionUtils;
import com.chixigua.chaos.utils.ErrorEnum;
import com.chixigua.chaos.utils.JsonResult;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.MediaType;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;

/**
 * @author dax
 * @since 2019/11/6 22:11
 */
public class SimpleAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {

        //todo your business

        CustomExceptionUtils.throwCustomException(response,JsonResult.errorJson(ErrorEnum.E_403));
    }
}